<template>
  <div class="user-diary">
    <div class="user-head">
      <div class="img-box">
        <img :src="userHead" alt="" />
      </div>
      <div class="personality">
        <p>“<span>{{personality}}</span>”</p>
      </div>
    </div>
    <div class="user-content">
      <div class="title">
        <p>
          {{ userMsg.yy }}年{{ userMsg.mm }}月{{ userMsg.dd }}日<span
            >星期{{ userMsg.weekend }}</span
          >
        </p>
        <p>
          <img src="../assets/images/flower.png" alt="" />
          <b>×</b><span> {{ userMsg.num }}</span>
        </p>
      </div>
      <div class="contentlist">
        <ul>
          <li>
            <span>{{ userMsg.h }}:{{ userMsg.m }}</span>
            <p v-for="(item, index) in userContent" :key="index">
              {{ item }}
            </p>
          </li>
        </ul>
      </div>
      <div class="author-name">
        <p>-- {{ userMsg.username }}</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "userdiary",
  data() {
    return {
      userHead: "",
      userMsg: {},
      userContent: "",
      personality:""
    };
  },
  mounted() {
    let index = this.$store.state.UserMsg.index;
    axios.get("/imgUrl.json").then((res) => {
      //   console.log(res.data[index]);
      this.userHead = res.data[index].imgurl;
    });

    axios.get("/userMsg.json").then((res) => {
      // console.log(res.data[index]);
      this.userMsg = res.data[index];
    }),
      axios.get("/userContent.json").then((res) => {
        let random = Math.floor(Math.random() * 8);
        // console.log(res.data[random]);
        this.userContent = res.data[random].content.split("&");
        // console.log(this.userContent);
        this.personality = res.data[random].personality;
        // console.log(this.personality);
      });
  },
};
</script>

<style lang="less" scoped>
.user-diary {
  width: 100%;
  padding-top: 20px;
  display: flex;
  .user-head {
    width: 350px;
    background-color: #fff;
    .img-box {
      width: 300px;
      height: 300px;
      padding: 3px 3px;
      box-sizing: border-box;
      box-shadow: 1px 1px 2px 1px #ccc;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .personality {
      width: 100%;
      margin: 15px 0;
      p {
        text-align: center;
        font-size: 30px;
        color: #808080;
        span {
            color: #303030;
            font-size: 20px;
        }
      }
    }
  }
  .user-content {
    width: 550px;
    position: relative;
    .title {
      display: flex;
      justify-content: space-between;
      border-bottom: 2px solid #8fa5ab;
      padding-bottom: 2px;
      p {
        span,
        b {
          color: #808080;
        }
        &:nth-of-type(1) {
          color: #808080;
          font-size: 19px;
          span {
            margin-left: 20px;
          }
        }
      }
      img {
        margin-right: 10px;
      }
    }
    .contentlist {
      padding-top: 20px;
      margin-bottom: 20px;
      span {
        color: #606060;
        font-size: 18px;
      }
      p {
        padding: 0 12px;
        margin-top: 5px;
        line-height: 24px;
        font-size: 16px;
        word-break: break-all;
        word-wrap: break-word;
      }
    }
    .author-name {
      position: absolute;
      bottom: 0;
      right: 20px;
      p {
        font-size: 16px;
        color: #808080;
        font-weight: bold;
        text-align: right;
      }
    }
  }
}
</style>